<%@ page language="java" contentType="text/html; charset=UTF-8"	pageEncoding="UTF-8"%>
<%
  String xm = this.getServletContext().getInitParameter("path");
	String path1 = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+"/"+xm;
%>  
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"> 
<html>
<head>
<title>销售机会列表</title>
<link href="<%=path1%>/css/css.css" rel="stylesheet" type="text/css" />
<link type="text/css" rel="stylesheet" href="<%=path1%>/scripts/pagekage/utils/widget/jqGrid/redmond/jquery-ui-1.8.2.custom.css"/>
<link type="text/css" rel="stylesheet" href="<%=path1%>/scripts/pagekage/utils/widget/jqGrid/ui.jqgrid.css"/> 
<script type="text/javascript" src="<%=path1%>/scripts/jquery-1.7.2.js"></script>
<script type="text/javascript" src="<%=path1%>/scripts/pagekage/utils/widget/jqGrid/jquery.jqGrid.src.js"></script>
<script type="text/javascript" src="<%=path1%>/scripts/pagekage/utils/widget/jqGrid/i18n/grid.locale-cn.js"></script>
<script type="text/javascript" src="<%=path1%>/scripts/pagekage/utils/widget/jqGrid/jquery.jqGrid.min.js"></script>
<!-- 日历 -->
<script type="text/javascript" src="<%=path1%>/scripts/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript">
$(document).ready(function(){
	
    $("#list4").jqGrid({
        url:"Sale_Chance/selectBySql.do",
        datatype:"json", 
        mtype:"POST",
        height:420,
        //postData:"{pageSize:10,pageIndex:1,SearchSql:''}",
        autowidth:true,
       // colNames:['ID', '名称', 'qq','操作'],
       colNames:['机会ID','机会名称','意向描述','房间ID','意向房间','状态','客户Id','客户姓名','客户电话','业务员ID','业务员编号','业务员'],
       colModel:[  
{name:'sale_chance_id',index:'sale_chance_id',hidden:true},
// {name:'',index:'', width:'3%', align:'center' , formatter: "checkbox",formatoptions:{disabled:false} } ,
{name:'sale_chance_name',index:'sale_chance_name', width:'15%', align:'left'},
{name:'intention_description',index:'intention_description', width:'25%', align:'center'},
{name:'room_id',index:'room_id', hidden:true},
{name:'room_code',index:'room_code', width:'5%', align:'center'},
{name:'state',index:'state', width:'5%'
	, align:'center'},
{name:'customer_id',index:'customer_id',hidden:true},
{name:'customer_name',index:'customer_name', width:'8%', align:'center'},
{name:'tel',index:'tel', width:'10%', align:'center'},
{name:'user_id',index:'user_id',hidden:true},
{name:'number',index:'number',width:'8%', align:'center'},
{name:'user_name',index:'user_name', width:'8%', align:'center'},
        ],
        rownumbers:true,
        //altRows:true,
        //sortname:'createDate',
        //sortorder:'asc',
        viewrecords: true,
        rowNum:8,
        rowList:[2,4,6,8,10,12],
        jsonReader:{
            id: "blackId",
            repeatitems : false
        },
        pager:$('#gridPager')
    });
    
    //selectNumber(number)
});
</script>
<script type="text/javascript">  
	       
	 
 
 function gotoAdd(){
	 window.location.href="addSale_Chance.jsp";
 }
    function gotoIndent(){ 
    	var id=$('#list4').jqGrid('getGridParam','selrow');
    	if(id==null)
    	{
    	alert("请选择要“转认购”的行");
    	return;
    	}
       var rowData = $('#list4').jqGrid('getRowData',id);
       updateid=rowData.sale_chance_id;
       var market={
    		   id:updateid,
    		   state:'转认购'
       }
       alert("updateid："+updateid);
       state=rowData.state;
       if(state=="草稿"){
    	   $.ajax({ 	
    	          data: market,
    	          type:"Post",  
    	          dataType: 'json',  
    	          url:"Sale_Chance/updateSale_ChanceState.do", 
    	          error:function(data){  
    	               alert("出错了！！");  
    	          }, 
    	          success:function(data){
    	          	alert('转认购成功！'); 
    	          	window.location.href='indentadd.jsp?id='+updateid;
    	           }  
    	           });  
       }else{
    	   alert("这个销售机会已转认购或签约，请重新选择！！");  
          
       }
    }
    function gotoBargain(){ 
    	var id=$('#list4').jqGrid('getGridParam','selrow');
    	if(id==null)
    	{
    	alert("请选择要“转签约”的行");
    	return;
    	}
       var rowData = $('#list4').jqGrid('getRowData',id);
       updateid=rowData.sale_chance_id;
       var market={
    		   id:updateid,
    		   state:'转签约'
       }
       alert("updateid："+updateid);
       state=rowData.state;
       if(state=="草稿"){
              $.ajax({ 	
              data: market,
              type:"Post",  
              dataType: 'json',  
              url:"Sale_Chance/updateSale_ChanceState.do", 
              error:function(data){  
                   alert("出错了！！");  
              }, 
              success:function(data){
              	//alert('转签约成功！'); 
              	window.location.href='bargainadd.jsp?id='+updateid;
               }  
               });  
       }else{
    	   alert("这个销售机会已转认购或签约，请重新选择！！");  
       
	    }
    }
    
    function ajaxUpdate(){  
    	
    	var id=$('#list4').jqGrid('getGridParam','selrow');
    	if(id==null)
    	{
    	alert("请选择要修改的行");
    	return;
    	}
       var rowData = $('#list4').jqGrid('getRowData',id);
       updateid=rowData.sale_chance_id;
       window.location.href = 'updateSale_Chance.jsp?id='+updateid;         
     }  
    
   
    function ajaxDelete(){  
    	
        var id=$('#list4').jqGrid('getGridParam','selrow');
        if(id==null)
        	{
        	alert("请选择要删除的行");
        	return;
        	}
        var rowData = $('#list4').jqGrid('getRowData',id);
        delid=rowData.sale_chance_id;
        alert(delid);

        $.ajax({  
        data: {sale_chance_id:delid},  
        type:"Post",  
        dataType: 'json',  
         url:"Sale_Chance/delete.do",  
         error:function(data){  
             alert("出错了！！");  
         },  
        success:function(data){  
        	$("#list4").jqGrid('setGridParam',{ 
                datatype:'json', 
                postData:{'pageSize':10,'pageIndex':1,'SearchSql':""}, // 发送数据   
                page:1 
            }).trigger("reloadGrid"); 
        	   
         }  
         });  
     } 
    function ajaxSelect(){  
        var SearchSql ="";
        var sale_chance_name=$("#sale_chance_name").val();
       // alert("sale_chance_name:"+sale_chance_name);
        var customer_name=$("#customer_name").val();
       // alert("customer_name:"+customer_name);
        var number=$("#number").val();
       // alert("number:"+number);
        var state=$("#state").val();
        alert("state:"+state);
          if(customer_name=="" && number=="" && sale_chance_name==""&& state=="" ){
        	  $("#list4").jqGrid('setGridParam',{ 
                  datatype:'json', 
                  postData:{'pageSize':10,'pageIndex':1,'Search':""}, // 发送数据   
                  page:1 
              }).trigger("reloadGrid"); 
          }else{
        	  if(customer_name!="" )
          	  {
          	     SearchSql +="  and customer_name like '%"+customer_name+"%'";
          	  }
        	  if(number!="" )
          	  {
          	     SearchSql +="  and number='"+number+"'";
          	  }
        	  if(sale_chance_name!="" )
          	  {
          	     SearchSql +="  and sale_chance_name like '%"+sale_chance_name+"%'";
          	  }
        	  if(state!="" )
          	  {
          	     SearchSql +="  and s.state='"+state+"'";
          	  }
          	$("#list4").jqGrid('setGridParam',{ 
              datatype:'json', 
              postData:{'SearchSql':SearchSql}, // 发送数据     //  where name like '%"+$("#name").val()+"%'
              url:"./Sale_Chance/selectBySql.do",
              page:1 
          }).trigger("reloadGrid");  
          }
           
     } 
    
</script> 
</head>
<body>
<div id="gridPager"></div>
<div class="yboxwidth boxcenter ybox01">
<div class="ybox09">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
       <td style="padding-left: 20px"><table border="0" cellspacing="0" cellpadding="0">
          <tr valign="top" >
            <td class="ybox11td5" ></td>
            <td class="ybox11td6" >销售机会列表</td>
            <td class="ybox11td7"></td>
            <td class="ybox11td2"></td>
            <td class="ybox11td3"></td>
            <td class="ybox11td2"></td>
            <td class="ybox11td3"></td>
            <td class="ybox11td2"></td>
            <td class="ybox11td4"></td>    
          </tr>
        </table></td>
        </tr>
    </table>
  </div>
  
  <div class="ybox02">
    <table width="100%" border="0" cellspacing="0" cellpadding="0" class="margb4">
      <tr>
        <td class="ybox03td1"></td>
        <td class="ybox03td2"></td>
        <td class="ybox03td3"></td>
      </tr>
      <tr>
        <td class="ybox03td4"></td>
        <td class="ybox03td5"><div class="ybox05 margb8">
          <dl>
            <dt> <strong></strong>&nbsp;&nbsp;
                  机会名称：<input type="text" id="sale_chance_name" />&nbsp;&nbsp;&nbsp;&nbsp;
                  客户姓名：<input type="text" id="customer_name"/> &nbsp;&nbsp;&nbsp;&nbsp;
	        业务员编号：<input type="text" id="number" />&nbsp;&nbsp;&nbsp;&nbsp;    
	        状态：<select id="state">
	        <option value=""></option>
	        <option value="草稿">草稿</option>
	        <option value="转认购">转认购</option>
	        <option value="转签约">转签约</option>
	        </select> &nbsp;&nbsp;&nbsp;&nbsp;
	       <img onclick="ajaxSelect()" src="images/bottonselect.gif" width="50" height="20" style="vertical-align: middle;cursor: pointer;" />
	           </dt>
          </dl>
        </div>
          <div class="ybox07 margb2">
            
      <dl><table border="0" cellspacing="0" cellpadding="0" class="ybox07table" >
              <tr align="left">
                <td class="ybox07td1" ><img src="images/op4_1.gif" width="15" height="16"/></td>
                <td ><span style="cursor:pointer;" onclick="gotoAdd()">添加销售机会信息</span></td>
                <td class="ybox07td2"><img src="images/op4_0.gif" /></td>
                <td class="ybox07td1"><img src="images/op4_6.gif" /></td>
                <td><span style="cursor:pointer;" onclick="ajaxUpdate()">修改销售机会信息</span></td>
                <td class="ybox07td2"><img src="images/op4_0.gif"  /></td>
                <td class="ybox07td1"><img src="images/op4_3.gif" /></td>
                <td><span style="cursor:pointer;" onclick="ajaxDelete()">移除销售机会信息</span></td>
                <td class="ybox07td2" width="45%"><img src="images/op4_0.gif" /></td>
                <td class="ybox07td2"><img src="images/op4_0.gif" /></td>
                <td class="ybox07td1" ><img src="images/op4_1.gif" width="15" height="16"/></td>
                <td ><span style="cursor:pointer;" onclick="gotoIndent()">转认购</span></td>
                <td class="ybox07td2"><img src="images/op4_0.gif" /></td>
                <td class="ybox07td1" ><img src="images/op6_1.gif" width="15" height="16"/></td>
                <td ><span style="cursor:pointer;" onclick="gotoBargain()">转签约</span></td>
              </tr>
          </table></dl></div>
          <table width="100%" border="0" cellpadding="0" cellspacing="1" class="ybox06table" id="list4">
                
              </table>
          </td>
        <td class="ybox03td6"></td>
      </tr>
      <tr>
        <td class="ybox03td7"></td>
        <td class="ybox03td8"></td>
        <td class="ybox03td9"></td>
      </tr>
    </table>
  </div>
</div>
</body>
</html>